Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slasher: Refactor and add tests #13589

Merged
merged 38 commits into from
Feb 9, 2024
Merged

Slasher: Refactor and add tests #13589

merged 38 commits into from
Feb 9, 2024

Conversation

nalepae
Copy link
Contributor

@nalepae nalepae commented Feb 6, 2024

Please read this PR commit by commit.

What type of PR is this?
Other

What does this PR do? Why is it needed?
This PR does not add any functional change, but:

  • Add some logs
  • Refactor some parts of the slasher (flatten happy path, variable renaming, etc...)
  • Fix some tests

The last commit adds new tests, with some commented failing tests.
For each failing test, a ticket issue is linked.

A next PR will fix these tickets:

@nalepae nalepae force-pushed the slasher-memory-leak-13430 branch 5 times, most recently from 6ccfb60 to b069820 Compare February 7, 2024 13:21
@nalepae nalepae marked this pull request as ready for review February 7, 2024 13:25
@nalepae nalepae requested a review from a team as a code owner February 7, 2024 13:25
@nalepae nalepae changed the title Improve slasher Slasher: Refactor and add tests Feb 7, 2024
@nalepae nalepae force-pushed the slasher-memory-leak-13430 branch 3 times, most recently from f0181f3 to ec50e01 Compare February 8, 2024 09:36
beacon-chain/slasher/chunks.go Outdated Show resolved Hide resolved
beacon-chain/slasher/receive.go Show resolved Hide resolved
Comment on lines 282 to 284
log.Errorf("No existing attestation record found for validator %d at target %d, while a surrounded vote was detected.",
validatorIdx, maxTarget,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid templated log messages, it makes it harder to monitor / aggregate these.

Prefer using logrus fields https://pkg.go.dev/github.com/sirupsen/logrus#Logger.WithFields

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in this commit: bd02048

groupedByValidatorChunkIndexAtts := s.groupByValidatorChunkIndex(atts)
log.WithField("numBatches", len(groupedByValidatorChunkIndexAtts)).Debug("Batching attestations by validator chunk index")
groupsCount := len(groupedByValidatorChunkIndexAtts)
batchDurations := make([]time.Duration, 0, len(groupedByValidatorChunkIndexAtts))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batchDurations is only used to calculate the totalBatchDuration. Why not just accumulate / update totalBatchDuration and skip this slice allocation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in this commit: 7acbc4d

nalepae and others added 24 commits February 9, 2024 15:33
Two tests were actually exactly the same.
Even if in this case the "happy" path means slashing.
It adds a few lines for callers, but it does not modify any more
arguments and it does what it says: getting a chunk.
Before this commit, there is two typse of `signing root`s floating around.
- The first one is a real signing root, aka a hash tree root computed from an object root and
a domain. This real signing root is the object ready to be signed.
- The second one is a "false" signing root, which is actually just the hash tree root of an object. This object is either the `Data` field of an attestation, or the `Header` field of a block.

Having 2 differents objects with the same name `signing root` is quite confusing.
This commit renames wrongly named `signing root` objects.
So it's clear for the user that the created attestation wrapper has an empty signature.
By testing `processAttestations` instead of `processQueuedAttestations`, we get rid of a lot of tests fixtures, including the 200 ms sleep.

The whole testing duration is shorter.
Some new failing tests are commented with a corresponding github issue.
Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM , thanks!

@nalepae nalepae added this pull request to the merge queue Feb 9, 2024
Merged via the queue into develop with commit af203ef Feb 9, 2024
17 checks passed
@nalepae nalepae deleted the slasher-memory-leak-13430 branch February 9, 2024 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants